package com.settlement.system.service.impl;

import com.settlement.system.model.entity.SysImportWorkingQueue;
import com.settlement.system.mapper.SysImportWorkingQueueMapper;
import com.settlement.system.service.SysImportWorkingQueueService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import org.springframework.util.Assert;
import com.settlement.system.common.util.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.settlement.system.model.query.SysImportWorkingQueueQuery;
import com.settlement.system.model.form.SysImportWorkingQueueForm;
import org.springframework.beans.BeanUtils;
import com.settlement.system.model.vo.SysImportWorkingQueueImportVo;

/**
 * <p>
 * 消息队列操作失败表 服务实现类
 * </p>
 *
 * @author huangrensen
 * @since 2024-08-30
 */
@Service
public class SysImportWorkingQueueServiceImpl extends ServiceImpl<SysImportWorkingQueueMapper, SysImportWorkingQueue> implements SysImportWorkingQueueService {

    @Override
    public Page<SysImportWorkingQueue> getPage(SysImportWorkingQueueQuery queryParams) {
        // 查询参数
        int pageNum = queryParams.getPageNum();
        int pageSize = queryParams.getPageSize();
        // 查询数据
        Page<SysImportWorkingQueue> page = new Page<>(pageNum, pageSize);
        return this.baseMapper.getPage(page, queryParams);
    }

     @Override
     public boolean saveSysImportWorkingQueue(SysImportWorkingQueueForm sysImportWorkingQueueForm) {
         SysImportWorkingQueue sysImportWorkingQueue = new SysImportWorkingQueue();
         BeanUtils.copyProperties(sysImportWorkingQueueForm, sysImportWorkingQueue);
         return this.saveOrUpdate(sysImportWorkingQueue);
     }

     @Override
     public SysImportWorkingQueueForm getSysImportWorkingQueueFormData(Long id) {
         SysImportWorkingQueue sysImportWorkingQueue = this.getById(id);
         SysImportWorkingQueueForm sysImportWorkingQueueForm = new SysImportWorkingQueueForm();
         BeanUtils.copyProperties(sysImportWorkingQueue, sysImportWorkingQueueForm);
         return sysImportWorkingQueueForm;
     }

     @Override
     public boolean deleteSysImportWorkingQueue(String ids) {
        Assert.isTrue(StringUtils.hasText(ids), "删除的数据为空");
        List<Long> idArray = Arrays.stream(ids.split(",")).map(Long::parseLong).collect(Collectors.toList());
        return this.removeByIds(idArray);
     }

    @Override
    public void importData(List<SysImportWorkingQueueImportVo> voList)  {
        List<SysImportWorkingQueue> sysImportWorkingQueueList = new ArrayList<>();
        for (SysImportWorkingQueueImportVo importVo : voList) {
            SysImportWorkingQueue sysImportWorkingQueue = new SysImportWorkingQueue();
            BeanUtils.copyProperties(importVo, sysImportWorkingQueue);
            sysImportWorkingQueueList.add(sysImportWorkingQueue);
        }
        this.saveOrUpdateBatch(sysImportWorkingQueueList);
    }

    @Override
    public List<SysImportWorkingQueueImportVo> findByIds(String idsStr) {
        if (!StringUtils.hasText(idsStr)) {
            return new ArrayList<>();
        }
        List<Long> ids = Arrays.stream(idsStr.split(",")).map(Long::parseLong).collect(Collectors.toList());
        List<SysImportWorkingQueue> sysImportWorkingQueueList = this.getBaseMapper().selectBatchIds(ids);
        List<SysImportWorkingQueueImportVo> voList = new ArrayList<>();
        for (SysImportWorkingQueue sysImportWorkingQueue : sysImportWorkingQueueList) {
            SysImportWorkingQueueImportVo vo = new SysImportWorkingQueueImportVo();
            BeanUtils.copyProperties(sysImportWorkingQueue, vo);
            voList.add(vo);
        }
        return voList;
    }
}
